home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Warrior’s Progress / source code / Source / Libraries / Application / ScreenPartMaker.cp < prev    next >
Encoding:
Text File  |  1997-06-28  |  2.1 KB  |  92 lines  |  [TEXT/CWIE]

  1. // ScreenPartMaker.cp
  2.  
  3. #ifndef ScreenPartMaker_h
  4. #include "ScreenPartMaker.h"
  5. #endif
  6. #ifndef NoScreenPart_h
  7. #include "NoScreenPart.h"
  8. #endif
  9. #ifndef Assert_h
  10. #include "Assert.h"
  11. #endif
  12. #ifndef SingleAllocator_h
  13. #include "SingleAllocator.h"
  14. #endif
  15. #ifndef MenuBarScreenPart_h
  16. #include "MenuBarScreenPart.h"
  17. #endif
  18. #ifndef SystemWindowScreenPart_h
  19. #include "SystemWindowScreenPart.h"
  20. #endif
  21. #ifndef WindowScreenPart_h
  22. #include "WindowScreenPart.h"
  23. #endif
  24. #ifndef AbstractWindow_h
  25. #include "AbstractWindow.h"
  26. #endif
  27.  
  28. #define MaxSize2(A,B)                    ( (sizeof(A)>sizeof(B)) ? sizeof(A) : sizeof(B) )
  29. #define MaxSize4(A,B,C,D)                ( (MaxSize2(A,B)>MaxSize2(C,D) ? MaxSize2(A,B) : MaxSize2(C,D) ) )
  30.  
  31. #define maxPartSize        MaxSize4( NoScreenPart, MenuBarScreenPart, SystemWindowScreenPart, WindowScreenPart )
  32.  
  33.  
  34. ScreenPart& ScreenPartMaker::MakeScreenPart( PointObject p )
  35.   {
  36.     WindowPtr window = 0;
  37.     int16 part = FindWindow( p, &window );
  38.     
  39.     switch ( part )
  40.       {
  41.         case inGrow:
  42.             Assert( window == FrontWindow() );
  43.             break;
  44.         
  45.         case inGoAway:
  46.         case inZoomIn:
  47.         case inZoomOut:
  48.             if ( window != FrontWindow() )
  49.                 part = inDrag;
  50.             break;
  51.       }
  52.  
  53.     static SingleAllocator< ScreenPart, maxPartSize > storage;
  54.     storage.DeleteAll();
  55.     
  56.     switch ( part )
  57.       {
  58.         case inDesk:
  59.             return *new( storage ) NoScreenPart;
  60.         
  61.         case inMenuBar:
  62.             return *new( storage ) MenuBarScreenPart;
  63.             
  64.         case inSysWindow:
  65.             return *new( storage ) SystemWindowScreenPart( window );
  66.  
  67.         case inContent:
  68.             return *new( storage ) WindowScreenPart( window, &AbstractWindow::ClickContent );
  69.  
  70.         case inDrag:
  71.             return *new( storage ) WindowScreenPart( window, &AbstractWindow::ClickDrag );
  72.  
  73.         case inGrow:
  74.             return *new( storage ) WindowScreenPart( window, &AbstractWindow::ClickGrow );
  75.  
  76.         case inGoAway:
  77.             return *new( storage ) WindowScreenPart( window, &AbstractWindow::ClickClose );
  78.  
  79.         case inZoomIn:
  80.             return *new( storage ) WindowScreenPart( window, &AbstractWindow::ClickZoomIn );
  81.  
  82.         case inZoomOut:
  83.             return *new( storage ) WindowScreenPart( window, &AbstractWindow::ClickZoomOut );
  84.  
  85.         default:
  86.             Assert( 0 );
  87.             break;
  88.       }
  89.     
  90.     return *new( storage ) NoScreenPart;
  91.   }
  92.